﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace ttbit.core
{

    public static class TexturePool
    {
        static Dictionary<string, Texture> mapTexture = new Dictionary<string, Texture>();
        /// <summary>
        /// NamedTexture 不是到处都有的
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>


        public static Texture GetTexture(string name)
        {
            return mapTexture[name.ToLower()];
        }


        public static Texture WhiteTexture
        {
            get;
            private set;
        }
        public static void Init()
        {

            {
                byte[] data = new byte[16];
                for (var i = 0; i < 16; i++)
                    data[i] = 255;
                WhiteTexture = new Texture(4, 4, IGL.TextureType.R_U8, data);
            }

            //using (var ms = Env.platform.CoreAssetReadAll("resource/core/logo.png"))
            //{
            //    var data = CoreLoadTool.LoadTextureData_RGBA(ms, out int w, out int h);
            //    var logo = new Texture((ushort)w, (ushort)h, IGL.TextureType.RGBA_32, data);
            //    TexturePool.AddNamedTexture("logo", logo);
            //}


        }

        public static void AddNamedTexture(string name, Texture tex)
        {
            mapTexture[name.ToLower()] = tex;
        }
        //public static List<Texture> LoadImagesByJson(string filename)
        //{
        //    List<Texture> texs = new List<Texture>();
        //    var code = System.IO.File.ReadAllText(filename);

        //    var infos = Newtonsoft.Json.Linq.JArray.Parse(code);
        //    var _path = System.IO.Path.GetDirectoryName(filename);
        //    foreach (JToken obj in infos)
        //    {
        //        var _imagepath = obj as JValue;
        //        if (_imagepath != null)
        //        {
        //            var _name = _imagepath.ToString();

        //            var _file = System.IO.Path.Combine(_path, _name);
        //            var key = System.IO.Path.GetFileNameWithoutExtension(_name).ToLower();
        //            Texture tex = LoadTexture(_file);
        //            mapTexture[key] = tex;
        //        }
        //    }
        //    return texs;

        //}


    }
}
